import os
import sys
import time
from urllib import parse
import traceback
import json
sys.stdout = open(os.devnull, 'w')
import jionlp as jio
sys.stdout = sys.__stdout__


argv = sys.argv[1:]

def jsonPrint(obj):
    print(json.dumps(obj))

def errorPrint(e:Exception, tracebackStr: str):
    jsonPrint({
        "error": str(e),
        "detail": tracebackStr
    })

if argv[0] == "parse_time":
    try:
        jsonPrint(jio.parse_time(argv[1], time_base=time.time()))
    except Exception as e:
        errorPrint(e, traceback.format_exc())